package com.bdqn.service;

import com.bdqn.base.mybatis.ServiceImpl;
import com.bdqn.mapper.ShopGoodsMapper;
import com.bdqn.pojo.ShopGoods;
import com.bdqn.pojo.ShopGoodsCountVO;
import org.springframework.stereotype.Service;

/**
 * 商品
 *
 * @author lilibo
 * @date 2021/10/09
 */
@Service
public class ShopGoodsServiceImpl extends ServiceImpl<ShopGoodsMapper, ShopGoods> implements ShopGoodsService {

    @Override
    public ShopGoodsCountVO getCountRate() {
        ShopGoodsCountVO shopGoodsCountVO = new ShopGoodsCountVO();
        // 获得订单表总数
        int userCount = baseMapper.selectCount(null);
        shopGoodsCountVO.setUserCount(userCount);
        // 今天新增订单量
        int todayAdd = baseMapper.getTodayAdd();
        // 昨天新增订单量
        int yesterdayAdd = baseMapper.getYesterdayAdd();
        // 前七天新增订单量
        int weekAdd = baseMapper.getWeekAdd();
        // 前七天新增订单平均值
        double weekAddAvg = weekAdd / 7.0;

        // 计算比昨天
        double yesterdayRate = 0;
        if (yesterdayAdd != 0) {
            yesterdayRate = (todayAdd - yesterdayAdd) / yesterdayAdd;
        }
        shopGoodsCountVO.setYesterdayRate(yesterdayRate);
        // 计算比七日
        double weekRate = 0;
        if (weekAddAvg != 0) {
            weekRate = (todayAdd - weekAddAvg) / weekAddAvg;
        }
        shopGoodsCountVO.setWeekRate(weekRate);
        return shopGoodsCountVO;
    }



}
